using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using System.Linq.Expressions;
using ACME.Northwind.Service.Interfaces;

namespace ACME.Northwind.WCFProxy
{
	/// <summary>
	/// The service implementation for Supplier object
	/// </summary>
	public partial class SupplierService : ISupplierService
	{
		#region ISupplierService Members

		/// <summary>
		/// Run a selection by the primary key
		/// </summary>
		public SupplierDTO SelectByPrimaryKey(int supplierid)
		{
			return DataService.Instance.GetSupplier(supplierid);
		}

		/// <summary>
		/// Run the persist for a list
		/// </summary>
		public bool Persist(List<SupplierDTO> list)
		{
			bool retval = true;
			foreach (SupplierDTO supplier in list)
			{
				retval &= this.Persist(supplier);
			}
			return retval;
		}

		/// <summary>
		/// Run the persist for an object
		/// </summary>
		public bool Persist(SupplierDTO dto)
		{
			return (DataService.Instance.PersistSupplier(dto) != null);
		}

		/// <summary>
		/// Run a selection using LINQ
		/// </summary>
		public List<SupplierDTO> RunSelect(string linq)
		{
			List<SupplierDTO> retVal = new List<SupplierDTO>();
			retVal.AddRange(DataService.Instance.GetSupplierListByLINQ(linq));
			return retVal;
		}

		/// <summary>
		/// Run a paginated selection using LINQ
		/// </summary>
		public PagedQueryResults<SupplierDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			return DataService.Instance.GetSupplierListPaged(pageIndex, pageSize, ascending, sortColumn, linq);
		}

		/// <summary>
		/// Run a selection for all objects
		/// </summary>
		public List<SupplierDTO> RunSelect()
		{
			List<SupplierDTO> retVal = new List<SupplierDTO>();
			DataServiceClient ds = DataService.Instance;
			retVal.AddRange(ds.GetSupplierList());
			return retVal;
		}

		/// <summary>
		/// Return a list of related Product objects
		/// </summary>
		public List<ProductDTO> GetProductList(SupplierDTO item)
		{
			List<ProductDTO> retval = new List<ProductDTO>();
			DataServiceClient ds = DataService.Instance;
			string s = "";
			s += "x.SupplierId = " + item.SupplierId + "";
			retval.AddRange(ds.GetProductListByLINQ("x => " + s));
			return retval;
		}

		/// <summary>
		/// Delete the specified item
		/// </summary>
		public bool Delete(SupplierDTO item)
		{
			DataServiceClient ds = DataService.Instance;
			return ds.DeleteSupplier(item);
		}

		#endregion
	}
}
